#!/usr/bin/env bash

set -e

if [ -z "$DEPENDABOT_NATIVE_HELPERS_PATH" ]; then
  echo "Unable to build, DEPENDABOT_NATIVE_HELPERS_PATH is not set"
  exit 1
fi

install_dir="$DEPENDABOT_NATIVE_HELPERS_PATH/npm_and_yarn"
mkdir -p "$install_dir"

helpers_dir="$(dirname "${BASH_SOURCE[0]}")"
cp -r \
  "$helpers_dir/lib" \
  "$helpers_dir/test" \
  "$helpers_dir/run.js" \
  "$helpers_dir/.eslintrc" \
  "$helpers_dir/jest.config.js" \
  "$helpers_dir/package.json" \
  "$helpers_dir/package-lock.json" \
  "$helpers_dir/patches" \
  "$install_dir"

cd "$install_dir"
npm ci --no-audit --fetch-timeout=600000 --fetch-retries=5 --no-dry-run --no-ignore-scripts
